﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DBSourceToolsLib.Suggestions
{
    public class TableAndAlias
    {
        private string m_TableName;

        public string TableName
        {
            get { return m_TableName; }
            set
            {
                // table name may come with schema as well.
                // for matching purposes, [SalesLT].[Product]
                // should return SalesLT.Product
                // where [Demo Table].ID
                // should remain delimited.
                string[] arrTableParts = value.Split('.');
                if (arrTableParts.Count() > 1)
                {
                    for (int i = 0; i < arrTableParts.Count(); i++)
                    {
                        string strTablePart = arrTableParts[i];
                        if (strTablePart.StartsWith("[") && strTablePart.EndsWith("]"))
                        {
                            if (strTablePart.Contains(' '))
                                m_TableName += (i > 0 ? "." : "") + strTablePart;
                            else
                            {
                                m_TableName += (i > 0 ? "." : "") + strTablePart.Substring(1, strTablePart.Length - 2);
                            }

                        }
                        else
                            m_TableName += (i > 0 ? "." : "") + strTablePart;
                    }
                }
                else
                    m_TableName = value;
            }
        }
        private string m_AliasName;

        public string AliasName
        {
            get { return m_AliasName; }
            set { m_AliasName = value; }
        }
    }
}
